#include <iostream>
#include "./lib/Eigen/SparseLU"
#include <fstream>

using namespace Eigen;
using namespace std;

int main(int argc, char * argv[]) {
    int dim = 119425;
    int line = 825737;
    SparseMatrix<double> mat(dim, dim);  
    VectorXd x(dim), b(dim);

    int row, column;
    double value;
    char tmp;

    fstream fs;

    fs.open(argv[1], ios::in);
    for (int i=0;i<line;i++) {
	fs >> row >> tmp >> column >> tmp >> value;
	mat.insert(row-1, column-1) = value;
    }
    fs.close();

    fs.open(argv[2], ios::in);
    for (int i=0;i<dim;i++) {
	fs >> value;
        b(i) = value;
    }
    fs.close();
    
    SparseLU<SparseMatrix<double>, COLAMDOrdering<int> > solver;
    solver.analyzePattern(mat); //计算排序置换向量
    solver.factorize(mat); //计算数值分解    
    x = solver.solve(b); //求解

    fs.open("res2", ios::out);
    fs << x << endl;
    fs.close();

    return 0;
}
